home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / tcpech1a / modmain.bas < prev    next >
BASIC Source File  |  1999-08-31  |  4KB  |  146 lines

  1. Attribute VB_Name = "modMain"
  2. Option Explicit
  3.  
  4. 'Constants
  5. Const MyModule = "modMain"
  6.  
  7. 'Variables
  8. Public Timings As Boolean
  9. Public QuitGame As Boolean
  10.  
  11. 'Classes - for every one you add, release in shutdown routine.
  12. Public Perf As clsPerformanceMonitor
  13. Public CScreen As clsScreen
  14. Public G As clsGlobal
  15.  
  16. 'Declares
  17. Public Declare Function timeGetTime Lib "winmm.dll" () As Long
  18. Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  19. Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Dest As Any, Src As Any, ByVal cb&)
  20.  
  21. 'Enums
  22. Public Enum enumLights
  23.     ltDisconnected = vbBlack
  24.     ltIdle = vbGreen
  25.     ltTCPUnspecifiedWriteError = &HFFFF00
  26.     ltTCPReadError = &H80FF
  27.     ltTCPSendError = vbRed
  28.     ltTCPSendTextError = vbYellow
  29.     ltTCPBlocked = vbBlue
  30. End Enum
  31.  
  32. Public Sub Main()
  33. '------------------------------------------------------------
  34. 'Main startup routine
  35. '------------------------------------------------------------
  36.     Const MyError = MyModule & "_" & "Main"
  37.     On Error GoTo Err_Init
  38.     
  39.     'Turn off timings
  40.     Timings = False
  41.     QuitGame = False
  42.     
  43.     'Initialize performance monitor class
  44.     Set Perf = New clsPerformanceMonitor
  45.     
  46.     'Initialize the 'global variable' class
  47.     Set G = New clsGlobal
  48.     
  49.     'Initialize the screen handler class
  50.     Set CScreen = New clsScreen
  51.     CScreen.Init
  52.     
  53.     'Initialize the TCP class
  54.     TCP.Init
  55.     
  56.     'Set the current time/date
  57.     G.StartTime = Now
  58.     G.CurrentTime = Now
  59.     
  60.     Exit Sub
  61.     
  62. Err_Init:
  63.     CScreen.DebugText = MyError & ": " & Err.Number & " - " & Err.Description
  64.     Resume Next
  65.     
  66. End Sub
  67.  
  68. Public Sub GameShutDown()
  69. '------------------------------------------------------------
  70. 'Shutdown routine
  71. '------------------------------------------------------------
  72. 'Turn off timings
  73.     Timings = False
  74.     
  75. 'Release all sockets
  76.     TCP.TCPShutDown
  77.     
  78. 'Release all classes
  79.     Set Perf = Nothing
  80.     Set CScreen = Nothing
  81.     Set G = Nothing
  82.     
  83. End Sub
  84.  
  85. Public Sub PerformanceStartTime(ByVal RoutineName As String)
  86. '------------------------------------------------------------
  87. 'Performance monitor start routine - call at beginning of procedure
  88. '------------------------------------------------------------
  89.     Const MyError = MyModule & "_" & "PerformanceStartTime"
  90.     On Error GoTo Err_Init
  91.  
  92.     If Perf(RoutineName).PerfStartTime = 0 Then
  93.         'dummy check to kick off an error if it doesn't exist.
  94.     End If
  95.     
  96.     With Perf(RoutineName)
  97.         .PerfStartTime = timeGetTime
  98.         .PerfHitCount = .PerfHitCount + 1
  99.     End With
  100.     
  101.     Exit Sub
  102.     
  103. Err_Init:
  104.     If Err.Number = 5 Then
  105.         'item already exists
  106.         Perf.Add RoutineName, 0, 0, 0, RoutineName
  107.         Resume Next
  108.     Else
  109.         CScreen.DebugText = MyError & ": " & Err.Number & " - " & Err.Description
  110.         Resume Next
  111.     End If
  112. End Sub
  113.  
  114. Public Sub PerformanceEndTime(ByVal RoutineName As String)
  115. '------------------------------------------------------------
  116. 'Performance monitor end routine - call at end of procedure
  117. '------------------------------------------------------------
  118.     Const MyError = MyModule & "_" & "PerformanceEndTime"
  119.     On Error GoTo Err_Init
  120.  
  121.     If Perf(RoutineName).PerfStartTime = 0 Then
  122.         'dummy check to kick off an error if it doesn't exist.
  123.     End If
  124.     
  125.     With Perf(RoutineName)
  126.         .PerfEndTime = timeGetTime
  127.         .PerfTotalTime = .PerfTotalTime + (.PerfEndTime - .PerfStartTime)
  128.     End With
  129.     
  130.     Exit Sub
  131.     
  132. Err_Init:
  133.     CScreen.DebugText = MyError & ": " & Err.Number & " - " & Err.Description
  134.     Resume Next
  135.  
  136. End Sub
  137.  
  138. Public Function Random(lowerBound As Long, upperBound As Long)
  139.     Const MyError = MyModule & "_" & "Random"
  140.     If Timings Then PerformanceStartTime MyError
  141.     Random = (Int((upperBound - lowerBound + 1) * Rnd + lowerBound))
  142.     If Timings Then PerformanceEndTime MyError
  143. End Function
  144.  
  145.  
  146.